package mm1.GUI;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.control.TextBox;
import javafx.scene.layout.HBox;
import javafx.scene.Group;
import javafx.scene.text.Text;
import javafx.scene.control.Label;
import javafx.ext.swing.SwingButton;
import javafx.scene.control.Slider;
import javafx.scene.media.MediaPlayer;
import javafx.geometry.VPos;
import javafx.geometry.HPos;
import javafx.scene.input.MouseEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.io.File;


/**
 * Layout for GUI elemnts for video control and audio slider
 *
 * @author Ralph Hoch, Matthias Heisler
 */


 
public class MediaPlayerControlsScreen extends CustomNode { 

    /**
     * test
     *
     */

    public var volumeSlider = Slider {
    	value: 75
       	max: 100
    }
    
    public var vds:VideoScreen;
    
    public var play:Boolean = false;
    
    public var openScreenVisible:Boolean = false;
    
    var state:Number = 0;
    var picturePath:String = "{new File("img/play_1.png").toURI()}";

	var play_1 = Image {
		url: picturePath
		//url: "{appPath}img/play_1.png"
		width: 40
		preserveRatio: true
	}
	
	var open_1 = Image {
	    url: "{new File("img/open_1.png").toURI()}"
		//url: "{appPath}img/open_1.png"
		width: 40
		preserveRatio: true
	}
	
	public override function create():Node {
		return Group {
            content: [
            	HBox {
        			height: bind scene.width * 0.1
        		   	content: [
						HBox {
		   				  	width: bind scene.width * 0.287
		   				   	content: [
		   						ImageView {
		   					   	image: open_1
			   					   	onMouseClicked: function(e: MouseEvent): Void {
			   					   		println("OPEN FILE");
			   					   		openScreenVisible = not openScreenVisible;
			   					   	}
		   					   	}
		   					]	   				
		   				}
						HBox {
			   			    hpos: HPos.CENTER
			   			    width: bind scene.width * 0.2
			   			    content: [
				           		ImageView {
		   					   	image: bind play_1
			   					   	onMouseClicked: function(e: MouseEvent): Void {
			   					   	    if (vds.player.media.source != null and vds.player.media.source.equals("") == false) {
				   					   	    if (state == 0) {
				   					   	        picturePath = "{new File("img/play_2.png").toURI()}";
				   					   	       	play_1 = Image {
				   					   	       		url: picturePath
				   					   	       		width: 40
				   					   	       		preserveRatio: true
				   					   	       	}
				   					   	        state = 1;
				   					   	    }
				   					   	    else if (state == 1) {
				   					   	        picturePath = "{new File("img/play_3.png").toURI()}";
   					   	        				play_1 = Image {
   					   	        					url: picturePath
   					   	        				   	width: 40
   					   	        					preserveRatio: true
   					   	        				}
				   					   	        state = 2;			   					   	        
				   					   	    }
				   					   	    else {
				   					   	      	picturePath = "{new File("img/play_1.png").toURI()}"; 
   					   	      	   				play_1 = Image {
   					   	      	   					url: picturePath
   					   	      	   					width: 40
   					   	      	   					preserveRatio: true
   					   	      	   				}
				   					   	      	state = 0;
				   					   	    }
				   					   		println("START/Pause VIDEO");
			                           	    println("Current Progress: {(100 * vds.player.currentTime) / vds.player.media.duration}");
			                              	if (vds.player.status == MediaPlayer.PAUSED) {
			                              	    println("PLAY");
			                              	    vds.player.play();
			                              	}
			                              	else {
			                              	    println("PAUSE");
			                              	    vds.player.pause();
			                              	}
			   					   	    }
			   					   	}
		   					   	}
				   			]	   				
			   			}
			   			HBox {
			   			    width: bind scene.width * 0.287
							translateY: 12
			   			    hpos: HPos.RIGHT
				   			content: [
					    		Label {text: "Volume"}
				        		volumeSlider
				        	]
			   			}
                   	]
                }
        	]
        }
	}

}